<?php

class UrVoteController extends Controller
{
	public function filters()
    {
        return array('accessControl');
    }
	public function accessRules()
    {
        return array(
            array('allow',
                'actions'=>array('add','delete'),
                'users'=>array('@'),
            ),
            array('deny',
                'users'=>array('*'),
            ),
        );
    }
    
	public function actionAdd()
	{	
		$ajax = getPost('ajax');
		$bid = getPost('bid');
		$uid = user()->id;
		$rate = getPost('rate');
		$desire = getPost('desire');
		$vote = new UrVote;
		$vote->bid = $bid;
		$vote->uid = $uid;
		$vote->rate = $rate;
		$vote->desire = $desire;
		$vote->create_datetime=time();
		$vote->update_datetime=time();
		
		if($vote->save()){
			if($ajax==1){
				echo 1;exit;
				}
			$this->redirect(referrer());
			}
	}

	public function actionDelete()
	{	
		$uid = getPost('uid');
		$bid = getPost('bid');
		$vote = UrVote::model()->find('uid=:uid and bid=:bid',array(':uid'=>$uid,':bid'=>$bid));
		if($vote->delete()){
			echo 1;
			}
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}
